package com.kiln.juxingqs.adapter

import androidx.recyclerview.widget.DiffUtil
import client.global.commlib.base.BasePagingAdapter
import client.global.commlib.base.PagingViewHoder
import com.kiln.juxingqs.R
import com.kiln.juxingqs.api.bean.HangOrderRecord
import com.kiln.juxingqs.api.bean.Zcjl
import com.kiln.juxingqs.api.bean.ZrAndSgRet
import com.kiln.juxingqs.databinding.LayoutItemMyGuadanBinding
import com.kiln.juxingqs.databinding.LayoutItemSgGuadBinding
import com.kiln.juxingqs.databinding.LayoutZrandsgitemBinding

class MyGuaDAndSgAdapter :
    BasePagingAdapter<HangOrderRecord.Order>(object :
        DiffUtil.ItemCallback<HangOrderRecord.Order>() {
        override fun areItemsTheSame(
            oldItem: HangOrderRecord.Order,
            newItem: HangOrderRecord.Order
        ): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(
            oldItem: HangOrderRecord.Order,
            newItem: HangOrderRecord.Order
        ): Boolean {
            return oldItem == newItem
        }
    }) {

    var type = 0
    var cOrder: ((b: HangOrderRecord.Order) -> Unit)? = null

    fun cancleOrder(b: HangOrderRecord.Order) {
        cOrder?.invoke(b)
    }

    var qrOrder: ((b: HangOrderRecord.Order) -> Unit)? = null

    fun querenOrder(b: HangOrderRecord.Order) {
        qrOrder?.invoke(
            b
        )
    }

    override fun bindItem(holder: PagingViewHoder, t: Any) {
        val binding = holder.binding as LayoutItemSgGuadBinding
        val bean = t as HangOrderRecord.Order
        binding.bean = bean
        binding.type = "${type}"
        binding.event = this

        when (bean.r_type) {
            1 -> binding.typeTxt = "挂单服务中心"
            2 -> binding.typeTxt = "挂单供应商"
        }
//        val time = bean.create_time.substring(
//            bean.create_time.length - 8,
//            bean.create_time.length - 3
//        )


        val time = bean.create_time.substring(5, bean.create_time.length - 3)

        binding.time = time
    }

    override fun getItemLayout(): Int {
        return R.layout.layout_item_sg_guad
    }
}